﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sagacity.Entity.Query;
using Coolite.Ext.Web;
using Sagacity.Entity.Build;

namespace Sagacity.NC.Web.BaokaoManager.HighSchool
{
    public partial class BatchBaseInfo : PageBase
    {
        #region 全局变量
        private Sagacity.Build.Application.Resource mResource = new Sagacity.Build.Application.Resource();
        private Sagacity.Build.Role mRole = new Sagacity.Build.Role();
        private Sagacity.Entity.Build.ResourceStyleInfo mResStyleInfo = null;
        private Sagacity.Entity.Build.ResourceInfo mResInfo = null;
        private Sagacity.Entity.Build.RoleInfo mRoleInfo = null;

        string batchId = "";
        int bStyleId =0;
        string ResourceId = "0";
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            batchId = string.IsNullOrEmpty(Request.QueryString["batchId"]) ? "0" : Request.QueryString["batchId"].ToString();
            ResourceId= string.IsNullOrEmpty(Request.QueryString["ResourceId"]) ? "0" : Request.QueryString["ResourceId"].ToString();
            hidBResouceId.Value = ResourceId;
            hidbatchId.Value = batchId;
            if (Page.IsPostBack == false)
            {
                GetStudentTitles();
                ShowBatchSimpleInfo();
            }
        }
        private void GetStudentTitles()
        {
            List<Sagacity.Entity.Build.ResourceInfo> resources = new List<Sagacity.Entity.Build.ResourceInfo>();
            int BResourceId=Convert.ToInt32(hidBResouceId.Value.ToString());
            resources.Add(mResource.GetResourceInfoById(BResourceId));

            List<Sagacity.Entity.Build.ResourceInfo> childs = mResource.GetChildResourceInfos(BResourceId, 1);
            resources.AddRange(childs);

            Repeater1.DataSource = resources;
            Repeater1.DataBind();
            if (resources.Count != 0)
            {
                //表示添加
                if (batchId == "0")
                {
                    string autoUrl = "BatchDetail.aspx";
                    tabBatchInfo.AutoLoad.Url = string.Concat(new object[] { autoUrl + "?batchId=", batchId, "&ResourceId=", ResourceId, "&showStyle=", 2 });
                }
                else
                {
                    //显示当前点击的节点
                    string autoUrl = resources[0].Id == Convert.ToInt32(ResourceId) ? "BatchDetail.aspx" : "BatchOtherInfo.aspx";
                    tabBatchInfo.AutoLoad.Url = string.Concat(new object[] { autoUrl + "?batchId=", batchId, "&ResourceId=", ResourceId, "&showStyle=", 2 });
                }
            }

        }
        #region  显示样式
        protected void ShowBatchSimpleInfo()
        {
            bStyleId = int.Parse(hidStyleId.Value);
            mResStyleInfo = mResource.GetObject<Sagacity.Entity.Build.ResourceStyleInfo>(bStyleId);
            mResInfo = mResource.GetResrouse(mResStyleInfo.ResourceId);
            if (batchId == "0")
            {
                Literal1.Text = mResStyleInfo.Content;
            }
            else
            {
                CreateHtml();
            }
        }
        private void CreateHtml()
        {
            Literal1.Text = "";
            Literal1.Text = Literal1.Text + CreateHtmlById();
            Literal1.Text = Literal1.Text + "\r\n<p class='prln'></p>\r\n&nbsp;&nbsp;\r\n";
        }
        private string CreateHtmlById()
        {
            mResInfo.Model.Filters.Add(new FilterInfo("BATCH_ID","=",batchId)) ;
            mRoleInfo = mRole.GetObject<RoleInfo>("from RoleInfo t where t.Id=" + base.CurrentUser.LoginRole.Id);
            return mResource.CreateStyleHTML(mResStyleInfo, mResInfo, mRoleInfo, "../Form/GetImage.aspx");
        }

     
#endregion 

    }
}
